package com.qjj.studydainty.util;
/*
 * Title:       <br>
 * Description: <br>
 *
 * @author 曲建金
 * @version 1.0
 */

import android.content.Context;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.qjj.studydainty.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author 曲建金
 */
public class MenuUtil {

    /**
     * 菜单图片
     **/
    private static int[] menu_image_array = {R.drawable.download, R.drawable.night, R.drawable.refresh,
            R.drawable.marker, R.drawable.history, R.drawable.exit};
    /**
     * 菜单文字
     **/
    private static String[] menu_name_array = {"下载", "夜间", "刷新", "添加书签", "历史、书签", "退出"};

    public static void showMenuDialog(final Context context, GridView menuGrid) {
        menuGrid.setAdapter(getMenuAdapter(context, menu_name_array, menu_image_array));
    }

    /**
     * 为menuGrid设置Adapter
     *
     * @param context            上下文
     * @param menuNameArray      命名
     * @param imageResourceArray 图片资源
     * @return 适配器
     */
    private static SimpleAdapter getMenuAdapter(Context context, String[] menuNameArray,
                                                int[] imageResourceArray) {
        ArrayList<HashMap<String, Object>> data = new ArrayList<>();
        for (int i = 0; i < menuNameArray.length; i++) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("itemImage", imageResourceArray[i]);
            map.put("itemText", menuNameArray[i]);
            data.add(map);
        }
        return new SimpleAdapter(context, data,
                R.layout.item, new String[]{"itemImage", "itemText"},
                new int[]{R.id.item_image, R.id.item_text});
    }
}